<?php
// +----------------------------------------------------------------------
// | 分销联盟-联盟信息管理页面
// +----------------------------------------------------------------------
// | Author: TongBC <50249101@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/03/06
// +----------------------------------------------------------------------
if(isset($_REQUEST['lists']) && $_REQUEST['lists']=='get'){

	include_once '/var/www/html/new/com.inc.php';
	include_once '/var/www/html/new/d/class/SimpleExcel.class.php';
	$sid  = $_SESSION['sid'];
	$ctn  = array('total'=>0, 'list'=>array());
	$role = array( 1=>'供销商', 2=>'供应商', 3=>'分销商' );
	$state= array('正常(已审核)', '已退出', '申请中','已驳回');
	// condition 
	$currentPage = $_REQUEST['last'] ? $_REQUEST['last']+0:1;
	$pageSize    = $_REQUEST['pageSize'] ? $_REQUEST['pageSize']+0:15;
	$startPos    = ($currentPage-1) * $pageSize;

	if(isset($_REQUEST['dstatus']) && $_REQUEST['dstatus']>-1) $condition = ' and u.dstatus='.($_REQUEST['dstatus'] + 0);
	if(isset($_REQUEST['dname']) && $_REQUEST['dname']) $condition.= ' and m.dname like "%'.addslashes($_REQUEST['dname']).'%"';
	$sql = "select u.memberID,u.dstatus,u.role_pledge,u.jointime,m.dname,u.audit_time,u.jointime from pft_union_member_info_SE u left join pft_member m on m.id=u.memberID where u.fid=$sid $condition limit $startPos,$pageSize";
	$GLOBALS['le']->query($sql);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$roleDt = explode('|', $row['role_pledge']);
		if(isset($_REQUEST['role']) && $_REQUEST['role']>0 && $roleDt[0]!=$_REQUEST['role']) continue;
		$row['role'] = $role[$roleDt[0]];
		$row['deposit'] = $roleDt[1]/100;
        $row['pledge_status'] = $roleDt[2];
		$ctn['list'][] = $row;
	}
	
	if(isset($_REQUEST['act'])){// 导出
		$Excel = array();
		$filename = date('YmdHis').'联盟成员';
		$Excel[0][] = '企业名称';
		$Excel[0][] = '会员类型';
		$Excel[0][] = '押金';
		$Excel[0][] = '状态';
		$Excel[0][] = '加入时间';
		$Excel[0][] = '审核时间';
		$i=1;
		foreach($ctn['list'] as $row){
			$Excel[$i][] = $row['dname'];
			$Excel[$i][] = $row['role'];
			$Excel[$i][] = $row['deposit'];
			$Excel[$i][] = $state[$row['dstatus']];
			$Excel[$i][] = $row['jointime'];
			$Excel[$i][] = $row['audit_time'];
			$i++;
		}
		$xls = new SimpleExcel('UTF-8', true,'联盟成员列表');
		$xls->addArray($Excel);
		$xls->generateXML($filename);
		exit;
	}
	
	// 统计
	$sql = "select count(u.id) as c from pft_union_member_info_SE u left join pft_member m on m.id=u.memberID where u.fid=$sid $condition";
	$GLOBALS['le']->query($sql);
	$GLOBALS['le']->fetch_assoc();
	
	$ctn['total'] = $GLOBALS['le']->f('c');
	$ctn['totalPage'] = ceil($ctn['total']/$pageSize);
	$ctn['last']  = $currentPage+1;
	exit(json_encode($ctn));
}





include '/var/www/html/new/d/common/header.html';
include '/var/www/html/new/d/common/left.html';
include '/var/www/html/new/d/tpl/alliance_mem/alliance_audit_today.tpl';
//include '/var/www/html/new/d/tpl/alliance_audit.tpl';
include '/var/www/html/new/d/common/footer.html';
